home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-STLport.exe / {app} / datafiles / lua_scripts / demo8.lua
Text File  |  2005-08-20  |  6KB  |  116 lines

  1. -----------------------------------------
  2. -- Start of handler functions
  3. -----------------------------------------
  4. -----------------------------------------
  5. -- Alpha slider handler (not used!)
  6. -----------------------------------------
  7. function sliderHandler(args)
  8.     CEGUI.System:getSingleton():getGUISheet():setAlpha(CEGUI.toSlider(CEGUI.toWindowEventArgs(args).window):getCurrentValue())
  9. end
  10.  
  11. -----------------------------------------
  12. -- Handler to slide pane
  13. --
  14. -- Here we move the 'Demo8' sheet window
  15. -- and re-position the scrollbar
  16. -----------------------------------------
  17. function panelSlideHandler(args)
  18.     local scroller = CEGUI.toScrollbar(CEGUI.toWindowEventArgs(args).window)
  19.     local demoWnd = CEGUI.WindowManager:getSingleton():getWindow("Demo8")
  20.  
  21.     scroller:setPosition(CEGUI.Relative, CEGUI.Point:new_local(0, scroller:getScrollPosition() / demoWnd:getRelativeHeight()))
  22.     demoWnd:setPosition(CEGUI.Relative, CEGUI.Point:new_local(0, -scroller:getScrollPosition()))
  23. end
  24.  
  25. -----------------------------------------
  26. -- Handler to set tip window text
  27. -----------------------------------------
  28. function tipHandler(args)
  29.     local tipWnd = CEGUI.WindowManager:getSingleton():getWindow("Demo8/Window2/Tips")
  30.     local tipstring = Tips[CEGUI.toWindowEventArgs(args).window:getName()]
  31.  
  32.     tipWnd:setText(tipstring)
  33. end
  34.  
  35. -----------------------------------------
  36. -- Handler to set preview colour when
  37. -- colour selector scrollers change
  38. -----------------------------------------
  39. function colourChangeHandler(args)
  40.     local winMgr = CEGUI.WindowManager:getSingleton()
  41.     
  42.     local r = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Red")):getScrollPosition()
  43.     local g = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Green")):getScrollPosition()
  44.     local b = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Blue")):getScrollPosition()
  45.     local col = CEGUI.colour:new_local(r, g, b, 1)
  46.  
  47.     CEGUI.toStaticImage(winMgr:getWindow("Demo8/Window1/Controls/ColourSample")):setImageColours(col)
  48. end
  49.  
  50.  
  51. -----------------------------------------
  52. -- Handler to add an item to the box
  53. -----------------------------------------
  54. function addItemHandler(args)
  55.     local winMgr = CEGUI.WindowManager:getSingleton()
  56.  
  57.     local text = winMgr:getWindow("Demo8/Window1/Controls/Editbox"):getText()
  58.     local cols = CEGUI.toStaticImage(winMgr:getWindow("Demo8/Window1/Controls/ColourSample")):getImageColours()
  59.  
  60.     local newItem = CEGUI.createListboxTextItem(text, 0, nil, false, true)
  61.     newItem:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
  62.     newItem:setSelectionColours(cols)
  63.  
  64.     CEGUI.toListbox(winMgr:getWindow("Demo8/Window1/Listbox")):addItem(newItem)
  65. end
  66.  
  67. -----------------------------------------
  68. -- Script Entry Point
  69. -----------------------------------------
  70. local guiSystem = CEGUI.System:getSingleton()
  71. local winMgr = CEGUI.WindowManager:getSingleton()
  72. local root = guiSystem:getGUISheet()
  73.  
  74. -- set default mouse cursor
  75. guiSystem:setDefaultMouseCursor("TaharezLook", "MouseArrow")
  76.  
  77. -- init the table we'll use to keep the added items 'alive'
  78. ListItems = {}
  79. ListItems.next = 0
  80.  
  81. -- init table of tips
  82. Tips = {}
  83. Tips["Demo8/Window1/Controls/Red"] = "Slider to adjust the red colour component."
  84. Tips["Demo8/Window1/Controls/Green"] = "Slider to adjust the green colour component."
  85. Tips["Demo8/Window1/Controls/Blue"] = "Slider to adjust the blue component."
  86. Tips["Demo8/Window1/Controls/Editbox"] = "Enter the text for a new list box item here."
  87. Tips["Demo8/Window1/Controls/Add"] = "Button to add a new item to the list box."
  88. Tips["Demo8/Window1/Controls/ColourSample"] = "Contains a sample of the selected colour."
  89. Tips["Demo8/Window1/Controls/ins1"] = "Contains brief instructions for the list box panel."
  90. Tips["Demo8/Window1"] = "Demo Window 1 - contains a simple Listbox demonstration."
  91. Tips["Demo8/Window2"] = "Demo Window 2 - contains some information panels."
  92. Tips["Demo8/Window2/Info"] = "Contains a description of this tips panel."
  93. Tips["Demo8/Window2/Tips"] = "Tips panel - will show brief information about the demo controls."
  94. Tips["Demo8/ViewScroll"] = "This scroll bar can be used to scroll the main view."
  95. Tips["Demo8/Window1/Listbox"] = "Listbox widget containing the items you have added."
  96.  
  97. -- subscribe required events
  98. winMgr:getWindow("Demo8/ViewScroll"):subscribeEvent("ScrollPosChanged", "panelSlideHandler")
  99. winMgr:getWindow("Demo8/Window1/Controls/Blue"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
  100. winMgr:getWindow("Demo8/Window1/Controls/Red"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
  101. winMgr:getWindow("Demo8/Window1/Controls/Green"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
  102. winMgr:getWindow("Demo8/Window1/Controls/Red"):subscribeEvent("MouseEnter", "tipHandler")
  103. winMgr:getWindow("Demo8/Window1/Controls/Green"):subscribeEvent("MouseEnter", "tipHandler")
  104. winMgr:getWindow("Demo8/Window1/Controls/Blue"):subscribeEvent("MouseEnter", "tipHandler")
  105. winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):subscribeEvent("MouseEnter", "tipHandler")
  106. winMgr:getWindow("Demo8/Window1/Controls/ins1"):subscribeEvent("MouseEnter", "tipHandler")
  107. winMgr:getWindow("Demo8/Window1/Controls/Editbox"):subscribeEvent("MouseEnter", "tipHandler")
  108. winMgr:getWindow("Demo8/Window1/Controls/Add"):subscribeEvent("MouseEnter", "tipHandler")
  109. winMgr:getWindow("Demo8/Window1"):subscribeEvent("MouseEnter", "tipHandler")
  110. winMgr:getWindow("Demo8/Window2"):subscribeEvent("MouseEnter", "tipHandler")
  111. winMgr:getWindow("Demo8/Window2/Info"):subscribeEvent("MouseEnter", "tipHandler")
  112. winMgr:getWindow("Demo8/Window2/Tips"):subscribeEvent("MouseEnter", "tipHandler")
  113. winMgr:getWindow("Demo8/ViewScroll"):subscribeEvent("MouseEnter", "tipHandler")
  114. winMgr:getWindow("Demo8/Window1/Listbox"):subscribeEvent("MouseEnter", "tipHandler")
  115. winMgr:getWindow("Demo8/Window1/Controls/Add"):subscribeEvent("Clicked", "addItemHandler")
  116.